home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / devices / modm0dev.zoo / modm0asm.s < prev    next >
Encoding:
Text File  |  1993-10-09  |  6.7 KB  |  354 lines

  1. |
  2. | modm0asm.s:
  3. |
  4. | Interrupt routines and low-level functions for the serial driver,
  5. | by T.Bousch
  6. |
  7. | See the file "COPYING" for distribution conditions.
  8. |
  9.  
  10. yamaha      = 0xFFFF8800
  11. mfp_gpip  = 0xFFFFFA01
  12. mfp_isra  = mfp_gpip + 14
  13. mfp_isrb  = mfp_gpip + 16
  14. mfp_rsr      = mfp_gpip + 42
  15. mfp_tsr      = mfp_gpip + 44
  16. mfp_udr      = mfp_gpip + 46
  17.  
  18. .globl _dtr_off, _dtr_on
  19. .globl _rts_off, _rts_on
  20. .globl _old_evt_timer, _carrier_monitor
  21. .globl _txrint, _rcvint, _txerror, _rxerror
  22. .globl _old_txrint, _old_rcvint, _old_txerror, _old_rxerror
  23. .globl _clear_errors, _check_errors
  24. .globl _dont_emit
  25. .globl _setstack
  26.  
  27. _dont_emit:    .word    0
  28. rts_state:    .word    0
  29. rx_oflow:    .word    0
  30. rx_errs:    .byte    0
  31. tx_errs:    .byte    0
  32.  
  33. |
  34. | Drop DTR line (hangup); same as Ongibit(4)
  35. |
  36.  
  37. _dtr_off:
  38.     movew    sr, d1
  39.     oriw    #0x700, sr
  40.     movel    #yamaha, a0    | soundchip register
  41.     moveb    #14, a0@    | no 14: port A
  42.     moveb    a0@, d0
  43.     bset    #4, d0        | set bit 4
  44.     moveb    d0, a0@(2)
  45.     movew    d1, sr
  46.     rts
  47.  
  48. |
  49. | Assert DTR line; same as Offgibit(4)
  50. |
  51.  
  52. _dtr_on:
  53.     movew    sr, d1
  54.     oriw    #0x700, sr
  55.     movel    #yamaha, a0
  56.     moveb    #14, a0@    | select port A
  57.     moveb    a0@, d0
  58.     bclr    #4, d0        | clear bit 4
  59.     moveb    d0, a0@(2)
  60.     movew    d1, sr
  61.     rts
  62.  
  63. |
  64. | Drop RTS line; same as Ongibit(3)
  65. |
  66.  
  67. _rts_off:
  68.     movew    sr, d1
  69.     oriw    #0x700, sr
  70.     movel    #yamaha, a0
  71.     moveb    #14, a0@    | select port A
  72.     moveb    a0@, d0
  73.     bset    #3, d0        | set bit 3
  74.     moveb    d0, a0@(2)
  75.     movew    #0, rts_state
  76.     movew    d1, sr
  77.     rts
  78.     
  79. |
  80. | Assert RTS line; same as Offgibit(3)
  81. |
  82.  
  83. _rts_on:
  84.     movew    sr, d1
  85.     oriw    #0x700, sr
  86.     movel    #yamaha, a0
  87.     moveb    #14, a0@    | select port A
  88.     moveb    a0@, d0
  89.     bclr    #3, d0        | clear bit 3
  90.     moveb    d0, a0@(2)
  91.     movew    #1, rts_state
  92.     movew    d1, sr
  93.     rts
  94.  
  95. |
  96. | The following routine is called periodically to set the hard_carrier
  97. | variable, and to wake processes selecting on a serial device when
  98. | the carrier is dropped. It also checks if there are pending data in
  99. | the transmission buffer, and if the reception buffer is below the
  100. | low water mark (so that it can assert RTS again).
  101. |
  102. | It hooks to the event_timer vector.
  103. |
  104.  
  105.     .long    0x58425241    | "XBRA"
  106.     .long    0x63756130    | "cua0"
  107. _old_evt_timer:
  108.     .long    0xDEADFACE    | old vector
  109.  
  110. _carrier_monitor:
  111.     moveml    d0-d1/a0-a1, sp@-
  112.     movew    sr, sp@-
  113.     oriw    #0x700, sr
  114.  
  115. |
  116. | Get the current carrier status in _hard_carrier
  117. |
  118.  
  119.     moveb    mfp_gpip, d0        | MFP i/o register
  120.     andw    #2, d0            | keep bit 1
  121.     eorw    #2, d0            | invert it
  122.     lsrw    #1, d0            | and shift
  123.     movew    d0, _hard_carrier
  124.  
  125.     tstl    _tx_buf_used        | any characters to transmit?
  126.     beq    L10
  127.     tstw    _dont_emit        | transmission blocked?
  128.     bne    L10
  129.     btst    #7, mfp_tsr        | is the MFP free?
  130.     beq    L10
  131.     bsr    transmit_byte        | ok, then transmit a byte
  132. L10:
  133.  
  134. |
  135. | RTS stuff: we allow reception if our rx_buffer is <= 1/4 full, and
  136. | forbid it if >= 3/4 full
  137. |
  138.  
  139.     tstw    _rts_cts        | shall we handle RTS ?
  140.     beq    L11
  141.  
  142.     movel    _rx_buf_used, a0    | how many bytes in the rx buffer?
  143.     tstw    rts_state        | is RTS currently on or off?
  144.     bne    Lrts1
  145. Lrts0:
  146.     cmpl    _rx_lowmark, a0        | rx_buf_used <= rx_lowmark ?
  147.     bgt    L11
  148.     bsr    _rts_on            | raise RTS to allow reception
  149.     bra    L11
  150. Lrts1:
  151.     cmpl    _rx_highmark, a0    | rx_buf_used >= rx_highmark ?
  152.     blt    L11
  153.     bsr    _rts_off        | drop RTS to stop reception
  154. L11:
  155.     movel    _rx_buf_used, a0    | how many bytes in the rx buffer?
  156.     movel    _rx_buf_end, d0
  157.     subl    #_rx_buf_start, d0    | buffer length
  158.     cmpl    d0, a0            | rx_buf_used <= RX_BUF_LENGTH ?
  159.     ble    L12
  160.     movew    #1, rx_oflow        | set the overflow flag
  161. L12:
  162.  
  163. |
  164. | And finally jump to old vector
  165. |
  166.  
  167.     movew    sp@+, sr
  168.     moveml    sp@+, d0-d1/a0-a1
  169.     movel    _old_evt_timer, sp@-
  170.     rts
  171.  
  172. |
  173. | Sends a byte to the MFP; make sure that all interrupts are disabled!!!
  174. |
  175.  
  176. transmit_byte:
  177.     movel    _tx_buf_tail, a0
  178.     moveb    a0@+, mfp_udr
  179.     cmpl    _tx_buf_end, a0
  180.     bne    L_nowrap
  181.     movel    #_tx_buf_start, a0    | don't forget the #
  182. L_nowrap:
  183.     movel    a0, _tx_buf_tail
  184.     subql    #1, _tx_buf_used
  185.     rts
  186.  
  187. |
  188. | Gets a byte from the MFP, all interrupts disabled
  189. |
  190.  
  191. receive_byte:
  192.     movel    _rx_buf_head, a0
  193.     moveb    mfp_udr, a0@+
  194.     cmpl    _rx_buf_end, a0
  195.     bne    L_nowrapr
  196.     movel    #_rx_buf_start, a0    | don't forget the #
  197. L_nowrapr:
  198.     movel    a0, _rx_buf_head
  199.     addql    #1, _rx_buf_used
  200.     rts
  201.     
  202. |
  203. | "Transmitter buffer empty" interrupt routine
  204. |
  205.  
  206.     .long    0x58425241    | "XBRA"
  207.     .long    0x63756130    | "cua0"
  208. _old_txrint:
  209.     .long    0xDEADFACE    | old vector
  210.  
  211. _txrint:
  212.     moveml    d0-d1/a0-a1, sp@-
  213.     oriw    #0x700, sr
  214.  
  215.     tstl    _tx_buf_used    | Any pending characters?
  216.     beq    L2
  217.     tstw    _dont_emit    | transmission blocked?
  218.     bne    L2
  219.     tstw    _rts_cts    | rts/cts mode?
  220.     beq    Lw2
  221.     btst    #2, mfp_gpip    | Clear to send?
  222.     bne    L2
  223. Lw2:
  224.     btst    #7, mfp_tsr    | MFP ready for a new char?
  225.     beq    L2
  226.     bsr    transmit_byte
  227. L2:
  228.     moveml    sp@+, d0-d1/a0-a1
  229.     bclr    #2, mfp_isra
  230.     rte
  231.     
  232. |
  233. | Receiver interrupt routine
  234. |
  235.  
  236.     .long    0x58425241    | "XBRA"
  237.     .long    0x63756130    | "cua0"
  238. _old_rcvint:
  239.     .long    0xDEADFACE    | old vector
  240.  
  241. _rcvint:
  242.     moveml    d0-d1/a0-a1, sp@-
  243.     oriw    #0x700, sr
  244.  
  245.     moveb    mfp_rsr, d0
  246.     andb    #0x78, d0    | keep bits 3, 4, 5, and 6
  247.     orb    d0, rx_errs
  248.     bsr    receive_byte
  249.     
  250.     moveml    sp@+, d0-d1/a0-a1
  251.     bclr    #4, mfp_isra
  252.     rte
  253.  
  254. |
  255. | Transmission error routine; the only interesting bit of the TSR is:
  256. |
  257. | bit 6: underrun error
  258. |
  259.  
  260.     .long    0x58425241    | "XBRA"
  261.     .long    0x63756130    | "cua0"
  262. _old_txerror:
  263.     .long    0xDEADFACE    | old vector
  264.  
  265. _txerror:
  266.     movel    d0, sp@-
  267.     oriw    #0x700, sr
  268.  
  269.     moveb    mfp_tsr, d0
  270.     andb    #0x40, d0    | keep bit 6
  271.     orb    d0, tx_errs
  272.  
  273.     movel    sp@+, d0
  274.     bclr    #1, mfp_isra
  275.     rte
  276.  
  277. |
  278. | Reception error routine; the interesting bits of the RSR are:
  279. |
  280. | bit 3: break detected
  281. | bit 4: frame error
  282. | bit 5: parity error
  283. | bit 6: overrun error
  284. |
  285.  
  286.     .long    0x58425241    | "XBRA"
  287.     .long    0x63756130    | "cua0"
  288. _old_rxerror:
  289.     .long    0xDEADFACE    | old vector
  290.  
  291. _rxerror:
  292.     moveml    d0-d1/a0-a1, sp@-
  293.     oriw    #0x700, sr
  294.  
  295.     moveb    mfp_rsr, d0
  296.     andb    #0x78, d0    | keep bits 3, 4, 5, and 6
  297.     orb    d0, rx_errs
  298.     bsr    receive_byte    | read data (clears RSR)
  299.     
  300.     moveml    sp@+, d0-d1/a0-a1
  301.     bclr    #3, mfp_isra
  302.     rte
  303.  
  304. |
  305. | User routine, calls the appropriate handlers
  306. |
  307.  
  308. _check_errors:
  309.     movel    d2, sp@-
  310.     moveb    tx_errs, d2    | any tx errors?
  311.     btst    #6, d2
  312.     beq    L40
  313.     jsr    _Underrun_Error
  314. L40:
  315.     moveb    rx_errs, d2    | any rx errors?
  316.     beq    L44        | no, skip all that
  317.     btst    #6, d2
  318.     beq    L41
  319.     jsr    _Overrun_Error
  320. L41:
  321.     btst    #5, d2
  322.     beq    L42
  323.     jsr    _Parity_Error
  324. L42:
  325.     btst    #4, d2
  326.     beq    L43
  327.     jsr    _Frame_Error
  328. L43:
  329.     btst    #3, d2
  330.     beq    L44
  331.     jsr    _Break_Detected
  332. L44:
  333.     tstw    rx_oflow
  334.     beq    L45
  335.     jsr    _Buffer_Overflow
  336. L45:
  337.     movel    sp@+, d2    | fall through
  338.  
  339. _clear_errors:
  340.     clrw    rx_oflow
  341.     clrb    rx_errs
  342.     clrb    tx_errs
  343.     rts
  344.  
  345. |
  346. | Set stack pointer (once again from S.Henson's Minixfs)
  347. |
  348.  
  349. _setstack:
  350.     movel    sp@+, a0    | return address in a0
  351.     movel    sp@, sp        | new stack pointer
  352.     subql    #4, sp        | because the caller will add 4 again
  353.     jmp    a0@        | and return
  354.